<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>人工销券</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">


</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>人工扣券</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="请选择..."  class="chosen-select" id="targetBrand">
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机号码：</label>
                            <div class="col-sm-8">
                                <input id="txt_phone" name="phone" class="form-control" type="text">
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请输入手机号</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">券额(元)：</label>
                            <div class="col-sm-8">
                                <input id="txt_gift_total" name="total" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="button" id="btn_save" onclick="doSave();"><i class="fa fa-check"></i> 确定</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
<script>
    $(function(){

        $('#targetBrand').chosen({   no_results_text : "未找到此选项!",width:"100%"});
        /**
         * 从 data参数中过滤数据
         */
        var url="${pageContext.request.contextPath}/jlcmt/queryBrandByAgent.ac";
        $.get(url,function(data){
            data=eval("("+data+")");

            var html='<option value=""></option>';
            for(var i=0;i<data.length;i++)
            {
                html+='<option value="'+data[i].brand_code+'">'+data[i].name+'</option>';
            }

            $("#targetBrand").html(html);
            $('#targetBrand').chosen({
                no_results_text : "未找到此选项!",
                width:"100%"
            });
            $("#targetBrand").trigger("chosen:updated");

        });

        //initTest();

        $("#btn_close1").click(function(){
            parent.layer.close(index);
        });
    });

    function doSave()
    {
        var isPass = true;
        isPass = validateNull($("#targetBrand"), isPass,"请选择商户!");
        isPass = validateNull($("#txt_phone"), isPass,"请填写手机号码!");
        isPass = validateNull($("#txt_gift_total"), isPass,"请填写劵额!");
        var phone=$("#txt_phone").val();
        var total=$("#txt_gift_total").val();
        var targetBrand=$("#targetBrand").val();
        if (isPass == true)
        {
            var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            if(!exp.test(total)){
               alert("请输入正确的劵额");
            }else{
                var url = "${pageContext.request.contextPath}/jlcmt/doManualTreatment.ac";
                $.ajax({
                    type: "post",
                    url: url,
                    data: {phone:phone,total:total,targetBrand:targetBrand},
                    dataType: 'json',
                    success: function(data) {
                        if(data.isok == true){
                            alert(data.msg);
                            window.location.href="${pageContext.request.contextPath}/jlcmt/toView.ac";
                        }else{
                            alert(data.msg);
                        }
                    }
                });
            }
        }
    }


    function validateNull(obj,isPass,error_info)
    {
        if(obj.val()=="")
        {
            isPass = false;
            showError(obj,error_info);
        }
        else
        {
            closeError(obj);
        }
        return isPass;
    }

    function showError(obj,error_info)
    {
        if(obj.closest('.form-group').hasClass('has-error') == false)
        {
            obj.parent().after("<div class='help-block'>"+error_info+"</div>");
            obj.closest('.form-group').removeClass('has-info').addClass('has-error');
        }
    }
    function closeError(obj)
    {
        if(obj.closest('.form-group').hasClass('has-error') == true)
        {
            obj.closest('.form-group').removeClass('has-error');//.addClass('has-info');
            obj.parent().next().remove();
        }
    }
</script>

</body>

</html>

